<%@page import="service.UserService"%>
<%@page import="entities.UserEntity"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";

	String userName = (String) session.getAttribute("userName");
	String action = request.getParameter("action");
	UserEntity user = new UserEntity();
	if (userName == null) {
		response.sendRedirect("../logReg.jsp?action=login");
	} else {
		user = UserService.getUser(userName);
	}
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title>用户信息-<%=user.getName()%></title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link rel="stylesheet" type="text/css"
	href="<%=basePath%>user/css/user.css">

<script type="text/javascript" src="<%=basePath%>js/jquery.min.js">
	
</script>
<script type="text/javascript" src="<%=basePath%>user/js/user.js">
	
</script>
</head>

<body>
	<jsp:include page="../header.jsp"></jsp:include>
	<div id="userName" style="height: 28px;"><%=userName%></div>
	<div id="action" style="display: none;"><%=action%></div>
	<div class="center">
		<div class="place">
			<a href="user/index.jsp"><%=userName%>的账户 </a> &gt; 基本信息
		</div>
		<div class="leftPanel">
			<div class="userInfo" id="UserInfo">
				<ul>
					<li><a title="设置头像" href="user/userInfo.jsp?action=head"><span id="userHead"
							style="display: none;"><%=user.getHeadImgUrl()%></span><img
							src="<%=user.getHeadImgUrl()%>" alt="头像"> </a>
						<h3>
							[<%=user.getName()%>]
						</h3> 性别：<%=user.getSex()%> <br /><%=user.getCampus()%>校区</li>
					<li><a class="name">手机号码：</a><a class="value"><%=user.getTel()%></a>
					</li>
					<li><a class="name">送餐地址：</a><a class="value"><%=user.getAddr()%></a>
					</li>
					<li><a class="name">注册时间：</a><a class="value"><%=user.getRegTime()%></a>
					</li>
				</ul>
			</div>
			<span class="seperateLine"></span>


			<div class="thirdNav">
				<ul>
					<li id="userInfo"><a href="user/userInfo.jsp?action=userInfo">基本资料</a>
					</li>
					<li id="head"><a href="user/userInfo.jsp?action=head">设置头像</a>
					</li>
					<li id="phone"><a href="user/userInfo.jsp?action=phone">设置手机号码</a>
					</li>
					<li id="password"><a href="user/userInfo.jsp?action=password">更改密码</a>
					</li>
				</ul>
			</div>

		</div>
		<div class="rightPanel">
			<%
				if ("head".equals(action)) {
			%>
			<div class="panelTitle">
				<a>头像设置</a>
			</div>
			<div id="altContent"></div>
			<script type="text/javascript"
				src="<%=basePath%>user/js/swfobject.js"></script>
			<script type="text/javascript">

			function uploadevent(status){
			     status += '';
			     $(".panelTitle").append(status);
				 switch(status){

					case '1':
						alert('头像保存成功!');
						//var time = new Date().getTime();
						 window.location.reload(true);
						//document.getElementById('avatar_priview').innerHTML = "头像1 : <img src='1.png?" + time + "'/> <br/> 头像2: <img src='2.png?" + time + "'/><br/> 头像3: <img src='3.png?" + time + "'/><br/> 原图: <img src='src.png?" + time + "'/>";
					break;

					case '2':
						if(confirm('js call upload')){
							return 1;
						}else{
							return 0;
						}
					break;

					case '-1':
						alert('取消!');
					break;
					case '-2':
						alert('头像保存失败，可能是图片太大!');
					break;

					default:
						alert(typeof(status) + ' ' + status);
				} 
			}

			var userHead =  $("#userHead").html().trim();
			if(userHead=="null"){
				userHead = "user/images/head/default.jpg";
			}
			var flashvars = {
			  "imgUrl":userHead,
			  "jsfunc":"uploadevent",
			  "pid":"75642723",
			  "uploadSrc":true,
			  "showBrow":true,
			  "showCame":true,
			  "uploadUrl":"servlet/UploadFileServlet?userName="+$("#userName").html().trim()
			};

			var params = {
				menu: "false",
				scale: "noScale",
				allowFullscreen: "true",
				allowScriptAccess: "always",
				wmode:"transparent",
				bgcolor: "#FFFFFF"
			};

			var attributes = {
				id:"FaustCplus"
			};

			swfobject.embedSWF("user/FaustCplus.swf", "altContent", "650", "500", "8.0.0", "expressInstall.swf", flashvars, params, attributes);

		</script>
			<%
				} else if ("userInfo".equals(action)) {
			%>
			<div class="panelTitle">
				<a>基本信息设置</a>
			</div>
			<ul>
				<li><a>送餐地址</a>
				</li>
				<li><input type="text" id="AddressTextBox" class="textBox"
					value="<%=user.getAddr()%>">
				</li>
				<li><a>性别</a>
				</li>
				<li><select name="sex" id="SexTextBox" class="textBox">
						<%
							if ("男".equals(user.getSex())) {
						%><option value="男" selected="selected">男</option>
						<option value="女">女</option>
						<%
							} else {
						%>
						<option value="男">男</option>
						<option value="女" selected="selected">女</option>
						<%
							}
						%>
				</select></li>
				<li><a>邮箱</a> <span style="color: red;" id="EmailTips"></span>
				</li>
				<li><input type="text" id="EmailTextBox" class="textBox"
					value="<%=user.getEmail()%>"></li>
				<li><a>校区</a>
				</li>
				<li><select name="campus" id="CampusTextBox" class="textBox">
						<%
							if ("厦门".equals(user.getCampus())) {
						%><option value="泉州">泉州</option>
						<option value="厦门" selected="selected">厦门</option>
						<%
							} else {
						%>
						<option value="泉州" selected="selected">泉州</option>
						<option value="厦门">厦门</option>
						<%
							}
						%>
				</select>
				</li>
				<li><a>其他</a>
				</li>
				<li><textarea id="OtherTextBox" class="textBox mulTextBox"
						rows="2" cols="20"></textarea>
				</li>
				<li><a style="color: red;" id="ChangeInfoTips"></a>
				</li>
				<li><input id="Button1" class="button" type="button" value="保存"
					onclick="changeUserInfo()">
				</li>
			</ul>
			<%
				} else if ("phone".equals(action)) {
			%>
			<div class="panelTitle">
				<a>电话设置</a>
			</div>
			<ul>
				<li><span id="PhoneTextBox" style="display: none;"><%=user.getTel()%></span>
				</li>
				<li><a>请输入电话号码</a>
				</li>
				<li><input type="text" id="PhoneTextBox1" class="textBox">
					<!-- <input type="button" value="发送验证码"> -->
				</li>

				<li><a style="color: red;" id="ChangePhoneTips"></a>
				</li>
				<li><input id="Button1" class="button" type="button" value="保存"
					onclick="changePhone()">
				</li>
			</ul>
			<%
				} else if ("password".equals(action)) {
			%>
			<div class="panelTitle">
				<a>密码设置</a>
			</div>
			<ul>
				<li><a>请输入新密码</a>
				</li>
				<li><input type="password" id="PasswordTextBox1"
					class="textBox"></li>
				<li><a>请再次输入密码</a>
				</li>
				<li><input type="password" id="PasswordTextBox2"
					class="textBox"></li>
				<li><a style="color: red;" id="ChangePasswordTips"></a>
				</li>
				<li><input id="Button1" class="button" type="button" value="保存"
					onclick="changePassword()">
				</li>
			</ul>
			<%
				}
			%>
		</div>
	</div>

	<jsp:include page="../footer.jsp"></jsp:include>

</body>
</html>
